package self.zhangkang.chart.tools

import self.zhangkang.chart.data.KLineInfo

/**
 * @author : Android-张康
 * created on: 2023/8/23 13:52
 * description:
 */
object DataTools {

    /**
     * 是否上涨
     *
     * @param kLineInfo 数据
     *
     * @return true 上涨 false 下跌
     */
    fun kLineInfoIsUp(kLineInfo: KLineInfo): Boolean {
        return if (kLineInfo.openPrice < kLineInfo.closePrice) {
            true
        } else if (kLineInfo.openPrice > kLineInfo.closePrice) {
            false
        } else {
            kLineInfo.openPrice >= kLineInfo.preCLosePrice
        }
    }

    /**
     * 除以复权因子
     */
    private fun timesFqFactor(value: String?, fqFactor: Float): String? {
        value ?: return null
        return value.toFloatOrNull()?.times(fqFactor)?.toString() ?: value
    }

    /**
     * 乘以复权因子
     */
    private fun divFqFactor(value: String?, fqFactor: Float): String? {
        value ?: return null
        return value.toFloatOrNull()?.div(fqFactor)?.toString() ?: value
    }
}